﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TrainingManagerSystem.WebUI.TrainingManagerSystemService;

namespace TrainingManagerSystem.WebUI.Controllers
{
    public class LanguageScoreController : Controller
    {
        private static List<Department> _listFullDepartment = new List<Department>();
        //
        // GET: /LanguageScore/
        readonly TrainingManagerSystemModelClient _services = new TrainingManagerSystemModelClient();
        public ActionResult Index(int? Id = null)
        {
            var languageScore = _services.ListLanguageScoreByLanguageType(80,1, null);
            var languageType = _services.ListAllLanguageType();
            ViewBag.LanguageType = languageType.ToList();
            ViewBag.Status = _services.ListAllStatusAccount().ToList();
            decimal numbPage = 0;
            foreach (var item in _services.ListAllDepartmentPaging(100, 1, 0))
            {
                _listFullDepartment.Add(item);
                numbPage = Math.Ceiling((decimal)item.TotalRow / 100);
            }
            for (int i = 1; i < numbPage; i++)
            {
                foreach (var item in _services.ListAllDepartmentPaging(100, i, 0))
                {
                    _listFullDepartment.Add(item);
                }
            }
            ViewBag.Department = _listFullDepartment;
            return View(languageScore.ToList());
        }
        public JsonResult Search(int pageSize,int currentPage,string accountName, string fullName, int departmentId, int statusAccountId, string score, bool finalType,int? languageTypeId = null)
        {
            var languageScore = _services.PagingLanguageScore(pageSize, currentPage, accountName, fullName, languageTypeId, score, departmentId, statusAccountId, finalType);
            var ls = from i in languageScore
                     select new { i.AccountName, i.FullName, i.DepartmentName, i.LanguageName, i.Score, i.Date, i.Note, i.LanguageScoreId,i.TotalRow};
            return Json(ls, JsonRequestBehavior.AllowGet);
        }
        public JsonResult ListLanguageScoreByType(int? languageTypeId)
        {
            var languageScore = _services.ListLanguageScoreByLanguageType(80, 1, languageTypeId);
            var ls = from i in languageScore
                     select new { i.AccountName, i.FullName, i.DepartmentName, i.LanguageName, i.Score, i.Date, i.Note, i.LanguageScoreId,i.TotalRow };
            return Json(ls, JsonRequestBehavior.AllowGet);
        }

        public JsonResult LanguageScoreDetail(int languageScoreId)
        {
            var language = _services.GetLanguageScoreDetailById(languageScoreId);
            return Json(language, JsonRequestBehavior.AllowGet);
        }

        public JsonResult ListLanguageScoreHistory(string accountName)
        {
            var languageScore = _services.LanguageScoresHistory(accountName);
            var ls = from i in languageScore
                     select new { i.Date, i.AccountName, i.LanguageName, i.Score, i.Note };
            return Json(ls, JsonRequestBehavior.AllowGet);
        }


        //QuyenNTH
        public PartialViewResult ListLanguageScoreHistoryReturnParital() {
            var data = _services.LanguageScoresHistory("QuynhND");
            return PartialView("_PersonLanguageScore",data );
        }

        [HttpPost]
        public JsonResult HistoryLanguageScoreByTypeAndEmployeeId(int languageTypeId, string employeeId) {
            var data = _services.HistoryLanguageScoreByTypeAndEmployeeId(languageTypeId, employeeId);
            return Json(data);
        }

        //End QuyenNTH
    }
}
